import request from "@/api";
import { BaseRet, ListRet, PageQuery, PageRet } from "../../response";
import { ApproveActionEnum, ApproveStatusEnum, WorkflowStatusEnum } from "@/enums/WorkflowEnum";

class WorkflowExampleApi {
  /**
   * 查询
   * @returns
   */
  static async query(data: WorkflowExampleQuery): Promise<PageRet<WorkflowExampleModel>> {
    return await request({
      url: "/workflowexample/query",
      method: "post",
      data: data,
    });
  }

  /**
   * 审批记录
   * @returns
   */
  static async getTimeLine(id: string): Promise<ApproveTimeLine[]> {
    return await request({
      url: `/workflowexample/getTimeLine/${id}`,
      method: "get",
    });
  }

  /**
   * 审批状态
   * @returns
   */
  static async getApproveStatusSelect(): Promise<EnumData[]> {
    return await request({
      url: `/workflowexample/getApproveStatusSelect`,
      method: "get",
    });
  }

  /**
   * 流程状态
   * @returns
   */
  static async getWorkflowStatusSelect(): Promise<EnumData[]> {
    return await request({
      url: `/workflowexample/getWorkflowStatusSelect`,
      method: "get",
    });
  }

  /**
   * 流程名称
   * @returns
   */
  static async queryFlowNameSelect(): Promise<string[]> {
    return await request({
      url: `/workflowexample/queryFlowNameSelect`,
      method: "get",
    });
  }

  /**
   * 新增
   * @returns
   */
  static async create(data: WorkflowExampleEdit): Promise<BaseRet> {
    return await request({
      url: `/workflowexample/create`,
      method: "post",
      data: data,
    });
  }

  /**
   * 修改
   * @returns
   */
  static async update(data: WorkflowExampleEdit): Promise<BaseRet> {
    return await request({
      url: `/workflowexample/update`,
      method: "post",
      data: data,
    });
  }

  /**
   * 提交
   * @returns
   */
  static async submit(id: string, flowName: string): Promise<BaseRet> {
    return await request({
      url: `/workflowexample/submit?id=${id}&flowName=${flowName}`,
      method: "get",
    });
  }

  /**
   * 取消
   * @returns
   */
  static async cancel(id: string): Promise<BaseRet> {
    return await request({
      url: `/workflowexample/cancel/${id}`,
      method: "get",
    });
  }
  /**
   * 删除
   * @returns
   */
  static async delete(id: string): Promise<BaseRet> {
    return await request({
      url: `/workflowexample/delete/${id}`,
      method: "get",
    });
  }

  /**
   * 审批
   * @returns
   */
  static async approve(data: BaseApproveInfo): Promise<BaseRet> {
    return await request({
      url: `/workflowexample/approve`,
      method: "post",
      data: data,
    });
  }
}

export interface WorkflowExampleModel extends BaseWorkflowInfo {
  bussinessName?: string;
  days?: number;
  submitter?: string;
}

export interface BaseWorkflowInfo {
  id?: string;
  submitTime?: string;
  submitUserId?: string;
  submitNickName?: string;
  workflowInstanceId?: string;
  workflowName?: string;
  workflowStatus?: WorkflowStatusEnum;
  workflowStatusText?: string;
  approveStatus?: ApproveStatusEnum;
  approveStatusText?: string;
  approveText?: string;
  approvedCount?: number;
  isEditForm?: boolean;
}

export interface WorkflowExampleEdit {
  id?: string;
  bussinessName?: string;
  days?: number;
}

export interface WorkflowExampleQuery extends PageQuery {
  searchString: string;
  approveStatus?: number;
  workflowStatus?: number;
  isSelfPending: boolean;
}

export interface BaseApproveInfo {
  id?: string;
  action?: ApproveActionEnum;
  remark?: string;
  tag?: string;
}

export interface ApproveTimeLine {
  id: string;
  time: string;
  action: string;
  remark: string;
  approvers: string;
  approved: string;
  message: string;
}

export interface EnumData {
  name: string;
  value: number;
  text: string;
}

export default WorkflowExampleApi;
